<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var

include_once(dirname(__FILE__) . "/../tools/smarty/libs/Smarty.class.php");					//--> out template
include_once("impl/MenuImpl.php");
include_once("impl/MenuGroupImpl.php");

require_once(dirname(__FILE__) . "/../controlHeader.php");					//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->

$oMenuImpl		= new MenuImpl(DB_TAG_SYSTEM);	//--> Menu
$oMenuGroupImpl	= new MenuGroupImpl(DB_TAG_SYSTEM);		//--> MenuGroup

$error_message 	= '';
$strMenuName 	= '';
$strMenuUrl		= '';
$strMenuRemark	= '';
$strGroupID		= '';


if(isset($_POST['Submit'])){
	$strGroupID 	= $_POST['groupid'];
	$strOrders 		= $_POST['orders'];
	$strMenuName 	= $_POST['menuName'];
	$strMenuUrl		= $_POST['menuUrl'];
	$strMenuRemark 	= $_POST['menuRemark'];
	
	if(empty($strGroupID))
		$error_message = 'The menu group ID should\'t be empty.';
	else if(empty($strMenuName))
		$error_message = 'The menu name should\'t be empty.';
	else if(empty($strMenuUrl)){
		$error_message = 'The menu url should\'t be empty.';
	}else{
		$isReturn = $oMenuImpl->add($strGroupID, $strOrders, $strMenuName, $strMenuUrl, $strMenuRemark);
		if($isReturn)
			$error_message = 'add successfully.';
		else 
			$error_message = 'add failure.';
	}
}

$sql = "SELECT id, name FROM menu_groups";
$arrMenuGroup = $oMenuGroupImpl->getHash(DB_TAG_SYSTEM, $sql);



/*----- out html -----*/
$smarty = new Smarty();					//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = CACHE_SYS_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrMenuGroup', $arrMenuGroup);
$smarty->assign('groupidS', $strGroupID);
$smarty->assign('orders', $strOrders);
$smarty->assign('menuName', $strMenuName);
$smarty->assign('menuUrl', $strMenuUrl);
$smarty->assign('menuRemark', $strMenuRemark);

$smarty->display('listMenu_Add.htm');
?>
